import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
import { AudioMgr } from './AudioMgr';

@ccclass('StartGame')
export class StartGame extends Component {
    start() {
        // this.playBgMusic()
    }

    update(deltaTime: number) {
        this.bgMove(deltaTime)
    }


    /**
     * 向下移动背景, 模拟hero向上飞行
     * 两张图片同时向下, 当下方图片超出屏幕后, 移动到上方
     */
    bgMove(dt: number) {

        // 循环判断两个背景
        for (const bgImg of this.node.children) {
            
            

            let p = bgImg.getPosition()
            // let p2 = bgImg.getWorldPosition()
            // console.log('背景坐标: ', p, p2)

            p.y -= 50 * dt;

            if(p.y <= -1100) {
                p.y += 1100 * 2
            }


            bgImg.setPosition(p)

        }

    }


    playBgMusic() {
        AudioMgr.inst.play('audio/game_music')
    }
}


